<?php
$access_level = 0;
$page_title = 'eTAT: Login';
require_once 'controller.php';
if(isset($_POST['login_submit'])) {
	$email = $_POST['email'];
	$password = makePassword($_POST['password']);
	$query = mysql_query("SELECT * FROM `instructor` WHERE `email`='$email' AND `password`='$password' AND `permission` = '2'") or die(mysql_error());
	$result = mysql_fetch_object($query);
	if($result) {
		$_SESSION['logged_in'] = $result->id;
		setcookie('etat_logged_in', $result->id, time()+COOKIE_TIME);
		unset($_SESSION['m']);
		redirect("home.php");
	} else {
		$_SESSION['m'] = 2;
		redirect("index.php");
	}
}
require_once 'header.php';
?>
<h1>Login to e-TAT</h1>
<?php
$form = new Form('login_form','post');
$form->textInput('email','Gmail Address',array('required'=>true));
$form->textInput('password','Password',array('type'=>'password','required'=>true));
$form->button('login_submit','Login',array('type'=>'submit'),false);
$form->button('login_cancel','Cancel',array('type'=>'button','onclick'=>'redirect("/")'),false);
print $form->build();
?>
<?php require_once 'footer.php'; ?>